package com.sapient.DAO;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

public class UserDAO {

	private String url = "jdbc:oracle:thin:@10.207.60.85:1521/XE";
	private String username = "surv";
	private String password = "surv";
	Connection conn;
	ResultSet rs;
	Statement st;
	String pass=null;
	String roll=null;
	String name=null;

	public void getConnection(){
		try {
			Class.forName("oracle.jdbc.driver.OracleDriver");

			conn= DriverManager.getConnection(url, username, password);

			st=conn.createStatement();
		}
		catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}


	}
	public boolean insertUser(String username, String password, String role) throws SQLException
	{
		getConnection();
		String query1="Select UserName from UserTable";
		rs=st.executeQuery(query1);

		while(rs.next()){
			String name=rs.getString("UserName");
			if(username.equals(name)){
				return true;
			}
		}
		String query= "Insert into UserTable (userid,username,userrole,password) values(UserSeq.nextval,"+"'"+username+"','"+role+"','"+password+"')";
		
		 try {
			st.executeQuery(query);
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
			return false;
		



	}

}

